package com.wz.project.bas.workShop.controller;

import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.project.bas.workShop.domain.BasWorkShop;
import com.wz.project.bas.workShop.service.WorkShopService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/bas/workShop")
public class WorkShopController extends BaseController {
    private String prefix = "bas/workShop";

    @Autowired
    WorkShopService workShopService;



    @RequiresPermissions("bas:workShop:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/workShop";
    }

    @PostMapping("/list")
    @ResponseBody
    public Object getList(BasWorkShop basWorkShop){

        startPage();
        List<BasWorkShop> list=workShopService.selectWorkShopList(basWorkShop);
        System.out.println(list);
        return getDataTable(list);
    }


    @Log(title = "项目管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody

    public AjaxResult remove(String ids)
    {
        return toAjax(workShopService.deleteWorkShopByIds(ids));
    }


    /**
     * 修改项目
     * @param workshop_id
     * @param mmap
     * @return
     */
    @RequiresPermissions("bas:warehouse:edits")
    @GetMapping("/edit/{workshop_id}")
    public String edit(@PathVariable("workshop_id") String workshop_id, ModelMap mmap)
    {
        BasWorkShop basWorkShop=workShopService.selectWorkShopByWorkShopId(workshop_id);
//        List<Prjgroup> prjgroups = prjGroupService.selectPrjgroupByDeptId(basWarehouse.getWarehouse_id());
        mmap.put("basWorkShop", basWorkShop);
//        mmap.put("prjgroups",prjgroups);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户
     */
    @RequiresPermissions("system:item:saveAndUpdate")
    @PostMapping("/saveAndUpdate")
    @ResponseBody
    public AjaxResult saveAndUpdate(@Validated BasWorkShop basWorkShop)
    {

        return toAjax(workShopService.saveAndUpdate(basWorkShop));
    }

    /**
     * 新增项目
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        /*mmap.put("roles", roleService.selectRoleAll().stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
        mmap.put("posts", postService.selectPostAll());*/
        return prefix + "/add";
    }

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BasWorkShop basWorkShop)
    {
//        item.setTheProblem("无");
        String s = String.valueOf(System.currentTimeMillis());
        String substring = s.substring(s.length() - 6);
//        int pejId = Integer.parseInt(substring);
        basWorkShop.setWorkshop_id(substring);
        return toAjax(workShopService.insertWorkShop(basWorkShop));
    }

}
